public class java6 {
    public static void main(String[] args) {
        String originalStr = "java woaijava,i liek jajavava,i enjoy java";
        String subStr = "java";

        String result = removeSubstring(originalStr, subStr);
        System.out.println("把" + subStr + "的内容删除后为:");
        System.out.println(result);
    }

    public static String removeSubstring(String originalStr, String subStr) {
        String[] words = originalStr.split(" ");
        StringBuilder sb = new StringBuilder();

        for (String word : words) {
            if (!word.equals(subStr)) {
                sb.append(word).append(" ");
            }
        }

        return sb.toString().trim();
    }
}
